<?php 
/**
*file CommentModel.class.php
*用户评论类
*
*@auther houtizong
*@version 1.0
*/
defined('ACC') ||exit ('ACC Denied');

class CommentModel extends Model{
	protected $table = 'comment'; 
	protected $pk = 'comment_id'; //主键

    //表中的所有字段 跟$_POST过来的字段匹配
	protected $_field = array(
		'comment_id','username','comment','art_id','user_id','nick','email','pubtime','ip'
		);		
	//自动填充
	//_get是自定义函数
	protected $_auto = array(
		    array('art_id','function','_get'),
		    array('ip','function','getRealIp'),
            array('pubtime','function','time')
		);
   //验证
    protected $_valid = array(
            array('nick',1,'用户名不能为空','require'),
            array('email',1,'邮箱输入有误','email')
       );

/**
*查询art_id下所有评论 
*@param int $id
*/
public function commentArt($id){
	$sql = 'select username,comment,nick,email,FROM_UNIXTIME(pubtime) as pubtime,INET_NTOA(ip) as ip from '.$this->table.' where art_id='.$id;
	return $this->db->getAll($sql);
}

/**
*查询总评论数  $total
*/
public function commTotal(){
	$sql = 'select count(*) from '.$this->table;
	return $this->db->getOne($sql);
}

/**
*查询所有评论 并分页
*@param $offset 偏移量
*@param $limit 显示数 
*return array[0]
*/
public function commList($offset=0,$limit=12){
	$sql = 'select comment_id,FROM_UNIXTIME(pubtime) as pubtime,art_id,comment,nick,username,email,ip from '.$this->table.
	' order by art_id desc limit '. $offset.','.$limit;
	return $this->db->getAll($sql);
}

/**
*获取评论用户IP-->写自定义函数里面
*/

/**
*获取文章id  comm-1用
*@param $id 主键
*@param string $art_id
*/





}
?>